package controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import po.DishAudit;
import service.DishAuditManager;

@Controller
@RequestMapping("/dish")
public class DishController {
	
	@Autowired
	private DishAuditManager dam;
	
	@RequestMapping("/list")
	public String listDishAudit(Model model){
		model.addAttribute("dishList", dam.listAllDishAudit());
		return "audit_dish";
	}
	
	@RequestMapping("/audit/{dId}/{status}")
	@ResponseBody
	public String changeDishStatus(@PathVariable String dId, @PathVariable int status){
		String sign;
		sign = dam.auditDish(dId, status);
		if(!sign.equals("0") && sign != null){
			return "{\"msg\" : \"SUCCESS\"}";
		} else {
			return "{\"error\" : \"operation failure\"}";
		}
	}
	
	@RequestMapping("/dishRecommendation")
	@ResponseBody
	public List<String> listRecommendedDish(){
		return dam.findRecommendDish();
	}
	
	@RequestMapping("/checkAudit/{mId}")
	public Map<String, Integer> listDishAuditByMId(@PathVariable String mId){
		return dam.listDishAuditByMId(mId);
	}
}
